import hashlib
import os


def distinct_list(ori_list: list):
    """
    去重后是无序的，重新按照以前的排序
    :param ori_list:
    :return:
    """
    temp_list = list(set(ori_list))
    temp_list.sort(key=ori_list.index)
    return temp_list


def file_split(filename):
    """
    文件名拆分
    :param filename:
    :return:
    """
    file_name, point, suffix = filename.rpartition('.')


def get_file_md5(file_name: str):
    """
    计算文件的md5
    :param file_name:
    :return:
    """
    m = hashlib.md5()
    with open(file_name, 'rb') as file_obj:
        while True:
            data = file_obj.read(4096)
            if not data:
                break
            m.update(data)
    return m.hexdigest()


def get_machine_area():
    """
    获取环境变量
    MACHINE_AREA=armtest
    :return:
    """
    for line in open('/etc/environment', 'r', encoding="utf-8"):
        if 'MACHINE_AREA' in line:
            line = line.replace('\n', '')
            return line.split('=')[1]
